<include file="public@header" />
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li class="active"><a href="{:url('area_manager/index')}">区域列表</a></li>
			<li><a href="{:url('area_manager/add')}">添加区域</a></li>
		</ul>
        <form class="well form-inline margin-top-20" method="get" action="{:url('area_manager/index')}">
            员工:
            <input type="text" class="form-control" name="name" style="width: 150px;" value="{:input('request.name/s','')}">
            联系电话:
            <input type="text" class="form-control" name="mobile" style="width: 150px;" value="{:input('request.mobile/s','')}">
            地址:
            <label class="form-inline">
				<select class="form-control" name="province_id" id="province" lay-ignore>
                    <option value="">请选择省</option>
                </select>
            </label>
            <label class="form-inline">
                <select class="form-control" name="city_id" id="city" lay-ignore>
                    <option value="">请选择市</option>
                </select>
            </label>
            <label class="form-inline">
                <select class="form-control" name="area_id" id="area" lay-ignore>
                    <option value="">请选择区</option>
                </select>
            </label>
            <input type="submit" class="btn btn-primary" value="搜索" />
            <a class="btn btn-danger" href="{:url('area_manager/index')}">清空</a>
        </form>
		<table class="table table-hover table-bordered">
			<thead>
				<tr>
					<th width="50">ID</th>
					<th>员工</th>
					<th>联系电话</th>
					<th>管理区域</th>
					<th width="140">{:lang('ACTIONS')}</th>
				</tr>
			</thead>
			<tbody>
				<foreach name="list" item="vo">
					<tr>
						<td>{$vo.id}</td>
						<td>{$vo.staff.name}</td>
						<td>{$vo.staff.mobile}</td>
						<td>{$vo.province.areaname}{$vo.city.areaname}{$vo.area.areaname}</td>
						<td>
							<a class="btn btn-xs btn-primary" href='{:url("area_manager/edit",array("id"=>$vo["id"]))}'>{:lang('EDIT')}</a>
                        	<a class="btn btn-xs btn-danger js-ajax-delete" href='{:url("area_manager/delete",array("id"=>$vo["id"]))}'>{:lang('DELETE')}</a>
						</td>
					</tr>
				</foreach>
			</tbody>
		</table>
		<div class="pagination">{$page}</div>
	</div>
	<script src="__STATIC__/js/admin.js"></script>
	<script type="text/javascript">
		function get_region_list(parentid,obj)
        {
            $.ajax({
                type:'get',
                url:'{:url("staff/get_region_list")}',
                data:{parentid:parentid},
                success:function(res){
                    var html = '<option value="">请选择</option>';
                    var json = eval(res.data);
                    for (var key in json) {
                    	html += '<option value="'+json[key].id+'" data-id="'+json[key].id+'">'+json[key].areaname+'</option>';
                    }
                    $('#'+obj).html(html);
                }
            });
        }

        get_region_list(0,'province');

        $('#province').change(function(){
            var id = $(this).find("option:selected").attr('data-id');
            get_region_list(id,'city');
            $('#area').html('<option value="">请选择</option>');
        });

        $('#city').change(function(){
            var id = $(this).find("option:selected").attr('data-id');
            get_region_list(id,'area');
        });

        setTimeout(function(){ $('#province').val('{:input("province_id")}').trigger('change'); }, 200);
        setTimeout(function(){ $('#city').val('{:input("city_id")}').trigger('change'); }, 400);
        setTimeout(function(){ $('#area').val('{:input("area_id")}'); }, 600);
	</script>
</body>
</html>